package cn.shyouchi.wuguanjia.android.ui.attendance.statistics;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.shyouchi.wuguanjia.android.R;

/**
 * Created by Eenie on 2016/12/20 at 13:10
 * Email: 472279981@qq.com
 * Des:
 */

public class StatisticErrorAdapter extends BaseQuickAdapter<StatisticsInfoEntity.ResultMessageBean, BaseViewHolder> {
    public StatisticErrorAdapter(List<StatisticsInfoEntity.ResultMessageBean> data) {
        super(R.layout.item_attendance_error_info_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, StatisticsInfoEntity.ResultMessageBean bean) {


        LinearLayout parent = holder.getView(R.id.linea_parent);


        holder.setText(R.id.tv_sign_time, String.format("%1s %2s - %3s", bean.getDate(), bean.getService().getStarttime(), bean.getService().getEndtime()));

        holder.setText(R.id.tv_sign_state, String.format("%1s", bean.getService().getServicesname()));


        parent.removeAllViews();
        if (bean.getStateDes().equals("异常")) {


            if (!TextUtils.isEmpty(bean.getCheckin().getDescription())) {
                View viewDes = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
                TextView tvDesTitle = (TextView) viewDes.findViewById(R.id.tv_title);
                TextView tvDesReason = (TextView) viewDes.findViewById(R.id.tv_reason);
                tvDesTitle.setText("异常描述");
                tvDesReason.setText(bean.getCheckin().getDescription());
                parent.addView(viewDes);
            }
            if (!TextUtils.isEmpty(bean.getSignback().getDescription())) {
                View viewDes = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
                TextView tvDesTitle = (TextView) viewDes.findViewById(R.id.tv_title);
                TextView tvDesReason = (TextView) viewDes.findViewById(R.id.tv_reason);
                tvDesTitle.setText("异常描述");
                tvDesReason.setText(bean.getSignback().getDescription());
                parent.addView(viewDes);
            }








            if (bean.getCheckin().getLate() == 2) {
                View view = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
                TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
                TextView tvReason = (TextView) view.findViewById(R.id.tv_reason);
                tvTitle.setText("异常原因");
                tvReason.setText(bean.getCheckin().getStatus());
                parent.addView(view);

                View view2 = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
                TextView tvTitle2 = (TextView) view2.findViewById(R.id.tv_title);
                TextView tvReason2 = (TextView) view2.findViewById(R.id.tv_reason);
                tvTitle2.setText("考勤地点");
                tvReason2.setText(bean.getCheckin().getAddress());
                parent.addView(view2);
            }
            if (bean.getSignback().getLate() == 2) {
                View view = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
                TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
                TextView tvReason = (TextView) view.findViewById(R.id.tv_reason);
                tvTitle.setText("异常原因");
                tvReason.setText(bean.getSignback().getStatus());
                parent.addView(view);


//                if (!TextUtils.isEmpty(bean.getSignback().getDescription())) {
//                    View viewDes = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
//                    TextView tvDesTitle = (TextView) viewDes.findViewById(R.id.tv_title);
//                    TextView tvDesReason = (TextView) viewDes.findViewById(R.id.tv_reason);
//                    tvDesTitle.setText("异常描述");
//                    tvDesReason.setText(bean.getSignback().getDescription());
//                    parent.addView(viewDes);
//                }


                View view1 = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
                TextView tvTitle1 = (TextView) view1.findViewById(R.id.tv_title);
                TextView tvReason1 = (TextView) view1.findViewById(R.id.tv_reason);
                tvTitle1.setText("考勤地点");
                tvReason1.setText(bean.getSignback().getAddress());
                parent.addView(view1);

            }


//            View view = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
//            TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
//            TextView tvReason = (TextView) view.findViewById(R.id.tv_reason);
//            tvTitle.setText("异常原因");
//            tvReason.setText(bean.getStateDes());
//            parent.addView(view);

        } else {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_error_sign_sub, null);
            TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
            TextView tvReason = (TextView) view.findViewById(R.id.tv_reason);
            tvTitle.setText("异常原因");
            tvReason.setText(bean.getStateDes());
            parent.addView(view);
        }

//        holder.setText(R.id.tv_sign_reason, String.format("%1s", bean.getStateDes()));
//        holder.setText(R.id.tv_sign_addr, String.format(" "));


    }
}
